package Thread;
//创建一个新的线程，让这个线程等待main线程结束后在结束该线程；
public class Demo16 {
    public static void main(String[] args) throws InterruptedException {
        Thread mainThread=Thread.currentThread();
        Thread t=new Thread(()->{
            try{
                System.out.println("开始等待主线程main结束");
                mainThread.join();
                System.out.println("结束等待主线程main");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        t.start();
        Thread.sleep(3000);
        System.out.println("main线程结束");
    }
}
